/**
 * This class contains unit tests for validating the behavior of Apex classes
 * and triggers.
  */
@isTest
private class TestContactTrigger 
{
    static testMethod void TestInsert() 
    {
        List<Contact> Contacts = new List<Contact>();       
        Account aa = new Account();
        aa.RecordTypeId =  SilCustomerHelper.GetLocalAdvertiserAccountRecordType();
        aa.Name='Sree';
        insert aa;
        
        Contact a;
        
        // Test 0       
        a = new Contact();
        a.FirstName = 'UnitTest';
        a.LastName = 'UnitTest';
        a.Phone = '1 800 GO FED EX';
        a.Primary_Indicator__c=false;
        a.RecordTypeId = SilCustomerHelper.GetLocalAdvertiserContactRecordType();
        a.Accountid= aa.id;
        Contacts.add(a);

        // Test 1       
        a = new Contact();
        a.FirstName = 'UnitTest3';
        a.LastName = 'UnitTest3';
        a.Primary_Indicator__c=false;
        a.Phone = null;
        a.RecordTypeId = SilCustomerHelper.GetLocalAdvertiserContactRecordType();
        a.Accountid= aa.id;
        Contacts.add(a);
        
        Test.startTest();
        insert Contacts;
        Test.stopTest();
        
        Map<ID, Contact> savedContacts = new Map<ID, Contact>([SELECT CleanPhoneText__c from Contact where ID in :Contacts]);
                    
        System.assertNotEquals(null, savedContacts.get(Contacts[0].ID).CleanPhoneText__c);
        System.assertEquals(null, savedContacts.get(Contacts[1].ID).CleanPhoneText__c);     
    }


    static testMethod void TesUpdate() 
    {
        List<Contact> Contacts = new List<Contact>();       
          Account aa = new Account();
        aa.RecordTypeId =  SilCustomerHelper.GetLocalAdvertiserAccountRecordType();
        aa.Name='Sree';
        insert aa;
        
        Contact a;
        
        // Test 0       
        a = new Contact();
        a.FirstName = 'UnitTest';
        a.LastName = 'UnitTest';
        a.Phone = '1 800 GO FED EX';
        a.Primary_Indicator__c=false;
        a.RecordTypeId = SilCustomerHelper.GetLocalAdvertiserContactRecordType();
          a.Accountid= aa.id;
        insert a;
        a.Phone = null;
        
        Contacts.add(a);
        
        // Test 1       
        a = new Contact();
        a.FirstName = 'UnitTest2';
        a.LastName = 'UnitTest2';
        a.Phone = null;
        a.Primary_Indicator__c=false;
        a.RecordTypeId = SilCustomerHelper.GetLocalAdvertiserContactRecordType();
         a.Accountid= aa.id;
        insert a;
        a.Phone = '(415) 888---39281';
         
        Contacts.add(a);
        
        Test.startTest();
        update Contacts;
        Test.stopTest();
        
        Map<ID, Contact> savedContacts = new Map<ID, Contact>([SELECT CleanPhoneText__c from Contact where ID in :Contacts]);
                    
        System.assertEquals(savedContacts.get(Contacts[0].ID).CleanPhoneText__c, null);
        System.assertNotEquals(savedContacts.get(Contacts[1].ID).CleanPhoneText__c, null);      
    }
    
}